package io.gitee.vexlife.snake.basic;

public class Node {
	private int x, y;

	public Node(int x, int y) {
		this.setX(x);
		this.setY(y);
	}

	public void setX(int x) {
		this.x = x;
	}

	public void setY(int y) {
		this.y = y;
	}

	public int getX() {
		return this.x;
	}

	public int getY() {
		return this.y;
	}
	
	@Override
	public boolean equals(Object obj) {
		try {
			return this.equalsTo(obj);
		}catch(UnexpectedComparisonWithNodeException e) {
			return false;
		}
	}

	public boolean equalsTo(Object obj) throws UnexpectedComparisonWithNodeException {
		if (obj instanceof Node) {
			return this.x == ((Node) obj).getX() && this.y == ((Node) obj).getY();
		} else if (obj instanceof int[]) {
			return this.x == ((int[]) obj)[0] && this.y == ((int[]) obj)[1];
		} else {
			throw new UnexpectedComparisonWithNodeException(obj);
		}
	}
}
